package com.maple.util;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import java.util.Locale;

@Component
public class LanUtil {
    private static MessageSource messageSource;
    public enum EnumLanKey{
        zh,en
    }

    public LanUtil(MessageSource messageSource) {
        LanUtil.messageSource = messageSource;
    }

    public static String getMsg(String messageKey) {
        return getMsg(messageKey, null);
    }

    public static String getMsg(String messageKey, String[] params) {
        return messageSource.getMessage(messageKey, params, LocaleContextHolder.getLocale());
    }

    public static String getMsg(String messageKey, String[] params, EnumLanKey lanKey) {
        return messageSource.getMessage(messageKey, params, new Locale(lanKey.name()));
    }

    public static String getMsg(String messageKey, String[] params, Locale locale) {
        return messageSource.getMessage(messageKey, params, locale);
    }

}
